#!/bin/bash

#
# Copyright (c) 2019-2020. TIBCO Software Inc.
# This file is subject to the license terms contained in the license file that is distributed with this file.
#

cp -R /tmp/src/*.cdd /opt/tibco/be/application
cp -R /tmp/src/* /opt/tibco/be/application
cp -R /tmp/src/* /opt/tibco/be/ext
mkdir -p /opt/tibco/be/application/ear

cp -R /tmp/src/*.ear /opt/tibco/be/application/ear
rm /opt/tibco/be/application/*.ear

if [ -e "/opt/tibco/be/application/dummy.txt" ]; then
    #Check App location have cdd or not
    CDD_LOCATION="/opt/tibco/be/application"
    cddCnt=$(find $CDD_LOCATION -name "*.cdd" | wc -l)
    if [ $cddCnt -ne 1 ]; then
        printf "ERROR: The given application location must have single CDD file\n"
        exit 1
    fi
fi

if [ -e "/opt/tibco/be/application/ear/dummy.txt" ]; then
    #Check App location have ear or not
    EAR_LOCATION="/opt/tibco/be/application/ear"
    earCnt=$(find $EAR_LOCATION -name "*.ear" | wc -l)
    if [ $earCnt -ne 1 ]; then
        printf "ERROR: The given application location must have single EAR file\n"
        exit 1
    fi
fi
